package org.example.etl.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.etl.entity.Aftn;
import org.example.etl.entity.Company;

@Mapper
public interface AFTNMapper extends BaseMapper<Aftn> {

    @Select(" SELECT COUNT(*) from company_number where acid=+#{acid}")
    public boolean isExistThisACID(String acid);

    @Select(" SELECT count(*) FROM kg_airlinecompany WHERE AIRCOMPANY_CODE3 = #{code3}")
    public boolean isExistThisCompany(String code3);

    @Insert("insert into company_number (acid,company_code3,company_name,delay_count) " +
            "values (#{company.getAcid()},#{company.getCompanyCode3()}," +
            "(select AIRCOMPANY_CNAME " +
            "from kg_airlinecompany " +
            "where AIRCOMPANY_CODE3 = #{company.getCompanyCode3()})," +
            "#{company.getDelayCount()});")
    public void createAnACIDMsg(Company company);


    @Update("update company_number set delay_count=#{company.getDelayCount()} where company_code3=#{company.getCompanyCode3()};")
    public void updateAnAcidDelayMsg(Company company) ;

    @Insert("insert into kg_aftn (acid,plan_height,execute_date,adep,ades) values (#{aftn.getAcid()},#{aftn.getPlanHeight()},#{aftn.getExecuteDate()},#{aftn.getAdep()},#{aftn.getAdes()})")
    public void insertAftn(Aftn aftn);
}
